package com.goods.controller.busniess;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.goods.business.service.ProductService;
import com.goods.common.model.business.ProductStock;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.business.ProductVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @description：
 * @version: 商品的api
 * @author：ruixinag
 * @create：Created in 2021/11/8 14:05
 */
@Api(tags = "业务模块-物资")
@RestController
@RequestMapping("/business/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    //物资资料分页列表展示
    @ApiOperation("物资资料分页列表展示")
    @GetMapping("/findProductList")
    public ResponseBean findProductList(
            @RequestParam Map paramMap
    ){
       //PageInfo<ProductVO> pageInfo= productService.findProductList(paramMap);
       //Map map=new HashMap();
       //map.put("rows",pageInfo!=null?pageInfo.getList():null);
       //map.put("total",pageInfo!=null?pageInfo.getSize():null);

        Map<String,Object> map=productService.findProductList(paramMap);

        return ResponseBean.success(map);
    }

    //添加物资信息
    @ApiOperation("添加物资信息")
    @PostMapping("/add")
    public ResponseBean add(
            @RequestBody ProductVO productVO
            ){
       productService.add(productVO);
        return ResponseBean.success();
    }

    //审核通过
    @ApiOperation("审核通过")
    @PutMapping("/publish/{id}")
    public ResponseBean publish(
            @PathVariable Long id
    ){
        productService.publish(id);
        return ResponseBean.success();
    }

    //回收站
    @ApiOperation("回收站")
    @PutMapping("/remove/{id}")
    public ResponseBean remove(
            @PathVariable Long id
    ){
        productService.remove(id);
        return ResponseBean.success();
    }

    //恢复
    @ApiOperation("恢复")
    @PutMapping("/back/{id}")
    public ResponseBean back(
            @PathVariable Long id
    ){
        productService.back(id);
        return ResponseBean.success();
    }

    //删除
    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(
            @PathVariable Long id
    ){
        productService.delete(id);
        return ResponseBean.success();
    }

    //编辑,回显数据
    @ApiOperation("编辑")
    @GetMapping("/edit/{id}")
    public ResponseBean<ProductVO> edit(
            @PathVariable Long id
    ){
      ProductVO productVO=  productService.edit(id);
        return ResponseBean.success(productVO);
    }

    //更新数据
    @ApiOperation("更新数据")
    @PutMapping("/update/{id}")
    public ResponseBean update(
            @PathVariable Long id,@RequestBody ProductVO productVO
    ){
         productService.update(id,productVO);
        return ResponseBean.success();
    }


    //findProducts,查找所有物资信息,分页展示
    @ApiOperation("查找所有物资信息,分页展示")
    @GetMapping("/findProducts")
    public ResponseBean findProducts(
            @RequestParam Map paramMap
    ){
        //PageInfo<ProductVO> pageInfo= productService.findProducts(paramMap);
        //PageInfo<ProductVO> pageInfo= productService.findProductList(paramMap);
        //Map map=new HashMap();
        //map.put("rows",pageInfo!=null?pageInfo.getList():null);
        //map.put("total",pageInfo!=null?pageInfo.getTotal():null);
        Map map= productService.findProductList(paramMap);

        return ResponseBean.success(map);
    }

    //返回库存数据,
    @ApiOperation("返回库存数据")
    @GetMapping(value = {"/findProductStocks"})
    public ResponseBean findProductStocks(
            @RequestParam Map paramMap
    ){
     PageInfo<ProductStockVO> pageInfo= productService.findProductStocks(paramMap);
        Map map=new HashMap();
        map.put("rows",pageInfo!=null?pageInfo.getList():new ArrayList<ProductVO>());
        map.put("total",pageInfo!=null?pageInfo.getTotal():null);
        return ResponseBean.success(map);
    }

    //返回所有库存数据,findAllStocks
    @ApiOperation("返回库存数据")
    @GetMapping(value = {"/findAllStocks"})
    public ResponseBean findAllStocks(
            @RequestParam Map paramMap
    ){
        PageInfo<ProductStockVO> pageInfo= productService.findProductStocks(paramMap);

        return ResponseBean.success(pageInfo.getList());
    }

}
